<template>
  <div style="width: 300px;margin: auto;margin-top: 300px">
    旧密码：<el-input v-model="euser" placeholder="请输入旧密码" style="margin-top: 20px;width: 200px"></el-input><br>
    新密码：<el-input v-model="xuser" placeholder="请输入新密码" style="margin-top: 20px;width: 200px"></el-input><br>
    确认新密码：<el-input v-model="xxuser" placeholder="请再次输入新密码" style="margin-top: 20px;width: 200px"></el-input>
    <el-button type="primary" @click="update" style="size: 20px;margin-left: 20px">确认</el-button>
  </div>

  <el-dialog
      v-model= "updateDiv"
      title=""
      width="20%"
      center>
    <h3>{{this.updates}}</h3>
    <el-button type="primary" @click="this.updateDiv=false" style="margin-top: 30px;margin-left: 100px;size: 20px" >确定</el-button>
  </el-dialog>
</template>

<script>
import axios from "axios";
export default {
data(){
     return{
     euser:"",
       xuser:"",
       xxuser:"",
       loginUser:{},
       updateDiv:false,
       updates:"",
     }
},
  methods:{
    getLoginUser(){
      axios.get("/project/user/getLoginUser").then(resp=>{
        this.loginUser=resp.data;
      })
    },
    update(){

      if (this.euser==this.xuser){
        this.updateDiv=true;
        this.updates="新旧密码不能一样"
      }
      else if(this.xuser!=this.xxuser){
        this.updateDiv=true;
        this.updates="二次新密码不一样";
      }else {
        axios.get("/project/user/updatePw",{params:{
            userId:this.loginUser.id,
            pwd:this.xuser
          }}).then(resp=>{
          if (resp.data=="ok"){
            this.updateDiv=true;
            this.updates="修改成功";

          }
        })
      }
    }
  },
  created() {
    this.getLoginUser();
  }
}
</script>

<style scoped>

</style>